@skypilot/sugarbowl
A collection of typed convenience functions for JavaScript & TypeScript.
All functions are typed, and it is expected that they will be used only in
type-checked code. This keeps the functions lightweight: they do not
carry the overhead of checking argument types or handling type coercion.
Exports
Array functions
flatten
getDuplicates
getFirstIntersection
getIntersection
includeIf
includes
omitSequentialDuplicateItems<I>(array: I[], { evaluate? }): I[]
pagesToIndices
pickRandomItem
pickRandomItems
pushIf
range(start: Integer, end: Integer): Integer[]
shuffle
toArray<T>(T | T[]): T[]
toUniqueArray
Date & time functions
isValidDate
sleep
toUnixTime(:Date, decimalPlaces?: Integer): number
toUnixTime(timestampInMs: number, decimalPlaces?: Integer): number
truncateIsoDateTime
Filesystem functions
findPackageFileDir
findUpTree
makeTempDir
readPackageFile
wipeDir
writeDataFile
writePackageFile
Higher-order functions
curry(fnToCurry: Function, ...args: any[]): Function
extendFunction(fnToExtend: Function, ...extendingFns: Function[]): Function
pipe(...fnsToPipe: Function[])
toMapFunction(...itemFns: Function[]): Function
Input/output functions
consoleIf(:boolean): (message: string) => void
Number functions
generateRandomInt(minValue: number, maxValue: number): Integer
isInteger(value: any): boolean
Object functions
entriesToKeyedItems(key: string, obj: object)
filterLeavesByKey(key: string, obj: object, options)
getOrDefault(obj: object, key: string, default: any)
isObject(value: any): boolean
mergeIf(conditional: any, :object)
omitFalsyEntries(obj: object): object
omitEntriesByValue(value: any, obj: object): object
omitUndefinedEntries(obj: object): object
setValueByPath(path: string | string[], value: any, target: object, options?)
swapKeysAndValues(obj: object): object
String functions
capitalizeAllWords(stringToCapitalize: string): string
<code>capitalizeFirstWord(stringToCapitalize: string): string
computeHash(stringToHash: string, length: Integer = 32): string
countOccurrences(str: string, substring: string): Integer
digitsOnly(stringToParse: string): string
inflectByNumber(howMany: number, singular: string, plural?: string): string
inflectQuantity(howMany: number, singular: string, plural?: string): string
isEnclosed(stringToCheck: string, startDelimiter: string, endDelimiter?: string = startDelimiter): boolean
nondigitsOnly(stringToParse: string): string
parseInteger(stringToParse: string, options): Integer
parseEnclosed(stringToParse: string, startDelimiter: string, endDelimiter: string = startDelimiter): string
randomAlphanumeric(length: Integer): string
removeExtraWhitespace(str: string): string
removeWhitespace(str: string): string
splitOnce(stringToSplit: string, splitter: string>): string[]
startsWith(string: string, substring: string, startFromPosition: Integer = 0): boolean
String.prototype
wrappers
padEnd
padStart
toLowerCase
toUpperCase
trim
trimLeft
trimRight